<?php include './application/views/common/zhs_header.php';?>

<?php include './application/views/common/zhs_usercenter_acnt.php';?>
<div class="inv_box w">
<?php include './application/views/common/zhs_usercenter_left.php';?>

  <div class="membd_right">
  <form id="message_form">
  <input type="hidden" name="is_receive" value="1">
<input type="hidden" id="status" name="status" value="1">
   <table width="788" class="zhs_letter_tab">
       <thead>
         <tr>
           <th colspan="6">收件箱 (共 <?php echo $msg_count;?> 封)</th>
         </tr>
       </thead>
       <tbody>
         <tr>
           <th><input style="margin-top:12px;" type="checkbox" value="全选" id="select_all" onclick="selectAll(this);"></th>
           <th>状态</th>
           <th>发件人</th>
           <th>内容</th>
           <th>时间</th>
           <th><input class="little_button" style="width:50px; margin:0;" type="button" value="删除" onclick="del();"></th>
         </tr>
           	<?php foreach ($list as $val){ ?>
  			<tr >
  				<td><input type="checkbox" name="id[]" value="<?php echo $val['id'];?>" /></td>
  				<?php if($val['fstatus'] ==1 ){?>
  				<td><img src="<?php echo CON_STATIC_URL; ?>zhsjr/images/con_23.gif"></td>
  				<?php }else{?>
  				<td><img src="<?php echo CON_STATIC_URL; ?>zhsjr/images/con_24.gif"></td>
  				<?php }?>
  				<td><?php echo $val['sent_username'] ? $val['sent_username'] : 'admin';?></td>
  				<td><span id="span_<?php echo $val['id'];?>" style="cursor: pointer;<?php if($val['fstatus']==0){echo "font-weight: bold;";}?>" onclick="view('<?php echo $val['id'];?>');"><?php echo $val['name'];?></span></td>
  				<td><?php echo date('Y-m-d H:i',$val['add_time']);?></td>
                <td></td>
  			</tr>
  		<?php }?>
       </tbody>
     </table>
     <div class="invbd_page"><td colspan="4" class="page" style="text-align: center;"><?php echo $this->pagination->create_links();?></td></div>
 </form>
  </div>
  
 <script>
function view(id){
	window.location='/message/zhs_view/'+id+'.html';
}

function del(){
	var options = {
		url : '/message/dodel',
		//clearForm :true,
		//resetForm :true,
		beforeSubmit:  checkForm,
		dataType: "json",
		type:"post",
		success : function(ret) {
			if(ret.msg==''){
				$('#dialog').dialog({
					modal:true,
					title:'系统提示',
					buttons:{"确定":function(){$(this).dialog("close");}},
					close: function() {
						//location=ret.data.url;
						if(ret.data.url==''){
							window.location.reload();
						}else{
							window.location=ret.data.url;
						}
					}
				}); 
				$("#msg").html("操作成功");
			}else{
				$('#dialog').dialog({
					modal:true,
					title:'系统提示',
					buttons:{"确定":function(){$(this).dialog("close");}},
					close: function() {
						$("#message_form").resetForm();
					}
				}); 
				$("#msg").html(ret.msg);
			}
		}
	};
	$("#message_form").ajaxSubmit(options);
	return false;
}

function read(status){
	$("#status").val(status);
	var options = {
		url : '/message/doread',
		beforeSubmit:  checkForm,
		dataType: "json",
		type:"post",
		success : function(ret) {
			if(ret.msg==''){
				$('#dialog').dialog({
					modal:true,
					title:'系统提示',
					buttons:{"确定":function(){$(this).dialog("close");}},
					close: function() {
						//location=ret.data.url;
						if(ret.data.url==''){
							window.location.reload();
						}else{
							window.location=ret.data.url;
						}
					}
				}); 
				$("#msg").html("操作成功");
			}else{
				$('#dialog').dialog({
					modal:true,
					title:'系统提示',
					buttons:{"确定":function(){$(this).dialog("close");}},
					close: function() {
						$("#message_form").resetForm();
					}
				}); 
				$("#msg").html(ret.msg);
			}
		}
	};
	$("#message_form").ajaxSubmit(options);
	return false;
}

function checkForm(){
	var form = document.getElementById("message_form");
	var g = false;
	for (var i=1;i<form.elements.length;i++)    {
		if(form.elements[i].type=="checkbox"){ 
            e=form.elements[i]; 
            if(e.checked==true){
				g = true;
            }
        } 
	}
	if(g==false){
		$('#dialog').dialog({
			modal:true, //蒙层（弹出会影响页面大小）
			title:'系统提示',
			buttons:{"确定":function(){$(this).dialog("close");}}
		}); 
		$("#msg").html("请先选择");
		return false;
	}else{
		$('#dialog').dialog({
			modal:true, //蒙层（弹出会影响页面大小）
			title:'系统提示'
		}); 
		$("#msg").html("处理中...");
		return true;
	}
}

function selectAll(obj){
	var form = document.getElementById("message_form");
	if(obj.checked==true){
		for (var i=1;i<form.elements.length;i++)    {
			if(form.elements[i].type=="checkbox"){ 
	            e=form.elements[i]; 
	            e.checked=true; 
	        } 
		}
	}else{
		for (var i=1;i<form.elements.length;i++)    {
			if(form.elements[i].type=="checkbox"){ 
	            e=form.elements[i]; 
	            e.checked=false; 
	        } 
		}
	}
}
</script>
</div> 

<?php include './application/views/common/zhs_footer.php';?>

<?php include './application/views/common/zhs_right.php';?>

